package edu.vt.tcga;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import edu.vt.tcga.clinical.ClinicalAliquot;
import edu.vt.tcga.clinical.ClinicalAnalyte;
import edu.vt.tcga.clinical.ClinicalPortion;
import edu.vt.tcga.clinical.ClinicalProtocol;
import edu.vt.tcga.clinical.ClinicalSample;
import edu.vt.tcga.clinical.ClinicalSlide;
import edu.vt.tcga.expression.level1.ExpressionFeatures;
import edu.vt.tcga.expression.level1.ExpressionStats;
import edu.vt.tcga.expression.level1.ExpressionParams;
import edu.vt.tcga.expression.level2.LowessNormalized;
import edu.vt.tcga.expression.level3.Analysis;
import edu.vt.tcga.methylation.level1.Methylation;
import edu.vt.tcga.methylation.level2.MethylationSignalIntensity;
import edu.vt.tcga.methylation.level3.MethylationAnalysis;
import edu.vt.tcga.snp.level3.SNPAnalysis;

public class HibernateUtil {

	private static final SessionFactory sessionFactory;
    static {
        try {
            sessionFactory = new AnnotationConfiguration()
                    .configure()
                    .addPackage("edu.vt.tcga")
                    .addAnnotatedClass(Analysis.class)
                    .addAnnotatedClass(LowessNormalized.class)
                    .addAnnotatedClass(ExpressionParams.class)
                    .addAnnotatedClass(ExpressionStats.class)
                    .addAnnotatedClass(ExpressionFeatures.class)

                    .addAnnotatedClass(Methylation.class)
                    .addAnnotatedClass(MethylationSignalIntensity.class)
                    .addAnnotatedClass(MethylationAnalysis.class)
                    
                    .addAnnotatedClass(ClinicalAliquot.class)
                    .addAnnotatedClass(ClinicalAnalyte.class)
                    .addAnnotatedClass(ClinicalPortion.class)
                    .addAnnotatedClass(ClinicalProtocol.class)
                    .addAnnotatedClass(ClinicalSample.class)
                    .addAnnotatedClass(ClinicalSlide.class)

                    .addAnnotatedClass(SNPAnalysis.class)

                    .buildSessionFactory();
        } catch (Throwable ex) {
            // Log exception!
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session getSession()
            throws HibernateException {
        return sessionFactory.openSession();
    }
}
